package twinb;

import ecologylab.xml.ElementState;
import ecologylab.xml.xml_inherit;
import winterwell.jtwitter.Twitter;
import winterwell.jtwitter.Twitter.Status;

@xml_inherit
public class Tweet extends ElementState
{
    // xml data
    @xml_leaf
    public String id;

    @xml_leaf
    public String cid;

    @xml_leaf
    public String createdAt;

    @xml_leaf
    public String text;

    @xml_leaf
    public String inReplyToTid;

    @xml_leaf
    public String inReplyToUid;

    @xml_leaf
    public String inReplyToUname;

    @xml_nested
    public Person user;

    // internal data
    private long   cvsId;

    public long getCid()
    {
        return cvsId;
    }

    public void setCid(long cid)
    {
        this.cvsId = cid;
        this.cid = String.valueOf(cvsId);
    }

    private Twinb host;
    private Twitter.Status status;

    public Status getStatus()
    {
        return status;
    }

    public Tweet(Twinb host, Twitter.Status status)
    {
        this.host = host;
        
        this.id = String.valueOf(status.getId());
        this.createdAt = status.getCreatedAt().toString();
        this.text = status.getText();
        this.inReplyToTid = String.valueOf(status.inReplyToStatusId);
        this.user=new Person(status.user);
        // TODO: assign these members
        this.inReplyToUid = "#######";
        this.inReplyToUname=  "#######";
        //this.setInReplyToUser(status.)
        this.status = status;
        this.cvsId = 0;
    }

    public long getTime()
    {
        return this.status.getCreatedAt().getTime();
    }

    public void setInReplyToUser(Person user)
    {
        this.user = user;
        this.inReplyToUid = String.valueOf(user.getId());
        this.inReplyToUname = user.getUser().getName();
    }
    
}
